/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package alarmlistener;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author rbs
 */
public class BackgroundServer {
    private Socket client;
    private BufferedReader input;
    private PrintWriter output;
    private ServerSocket server;
    private Logger logger;

    public BackgroundServer() throws IOException
    {
        logger = Logger.getLogger(BackgroundServer.class.toString());
        logger.setLevel(Level.ALL);
        logger.log(Level.FINE, "Starte Server");
        server = new ServerSocket(10114);
        logger.log(Level.FINE, "Server gestartet");

    }

    public String readLine() throws IOException
    {
        return input.readLine();
    }

    public void sendLine(String send)
    {
            output.println(send);
            output.flush();
    }

    public void conNewClient() throws IOException
    {
        Logger logger = Logger.getLogger(this.getClass().getName());
        logger.log(Level.FINE,"Waiting for new Client");
        client = server.accept();
        logger.log(Level.FINE,"Client connected");
        input = new BufferedReader(new InputStreamReader(client.getInputStream()));
        output = new PrintWriter(client.getOutputStream(), true);
    }

}
